package gw.com.android.ui.news;

import android.text.TextUtils;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;

import www.com.library.util.StringFormatter;

/**
 * @author jett
 * @since 2017-12-05.
 */
public class CalendarArgs {

    public static final String STATUS_PUBLIC = "1";
    public static final String STATUS_PRIVATE = "0";

    public static final String TYPE_DATA = "1";
    public static final String TYPE_EVENT = "2";
    public static final String TYPE_VACATION = "3";

    public Calendar calendar;
    public List<String> countries; //countrys   中文名
    public String status;  //状态 1：已公布 0：未公布
    public List<String> level; //重要等级 1,2,3 4,5
    public List<String> types;  //约定：1 为数据  2为事件， 3为假期

    public void setTypes(List<String> types) {
        this.types = types;
    }

    public String getTime() {
        if (calendar == null) {
            calendar = Calendar.getInstance();
        }
        return StringFormatter.instance().toDate(calendar.getTime());
    }

    public void addCountry(String country) {
        if (countries == null) {
            countries = new ArrayList<>();
        }
        countries.add(country);
    }

    public void removeCountry(String country) {
        if (countries != null) {
            countries.remove(country);
        }
    }

    public void addLevel(String level) {
        if (this.level == null) {
            this.level = new ArrayList<>();
        }
        this.level.clear();
        this.level.add(level);
    }

    public void removeLevel(String level) {
        if (this.level != null) {
            this.level.remove(level);
        }
    }

    public void addType(String type) {
        if (this.types == null) {
            this.types = new ArrayList<>();
        }
        this.types.add(type);
    }

    public void removeType(String type) {
        if (this.types != null) {
            this.types.remove(type);
        }
    }

    public String getCountries() {
        if (countries != null && !countries.isEmpty()) {
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < countries.size(); i++) {
                sb.append(countries.get(i));
                if (i != countries.size() - 1) {
                    sb.append(",");
                }
            }
            return sb.toString();
        }
        return null;
    }

    public String getTypes() {
        if (types != null && !types.isEmpty()) {
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < types.size(); i++) {
                sb.append(types.get(i));
                if (i != types.size() - 1) {
                    sb.append(",");
                }
            }
            return sb.toString();
        }
        return null;
    }

    public String getLevels() {
        if (level != null && !level.isEmpty()) {
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < level.size(); i++) {
                sb.append(level.get(i));
                if (i != level.size() - 1) {
                    sb.append(",");
                }
            }
            return sb.toString();
        }
        return null;
    }

    public boolean isEmpty() {
        if (calendar != null) {
            return false;
        }
        if (countries != null && !countries.isEmpty()) {
            return false;
        }
        if (level != null && !level.isEmpty()) {
            return false;
        }
        if (types != null && !types.isEmpty()) {
            return false;
        }
        return TextUtils.isEmpty(status);
    }

}
